package com.flute.haflute.jobbox.child;

import com.flute.haflute.jobbox.common.CloudContext;

/**
 * 子节点特定环境保存在这里
 */
public class ChildContext {

	/** 子节点的唯一编号：String */
	private static String myID;

	/** 子节点的全局号，主节点分配 */
	private static int daemonNo = -1;

	/** 设置DaemonNo */
	public static void setDaemonNo(String sDaemonNo) {
		myID = CloudContext.getChildIdPattern()
				.replaceAll("ip", CloudContext.getLocalIP())
				.replaceAll("dno", sDaemonNo);
		daemonNo = Integer.parseInt(sDaemonNo);
	}

	/** 获得DaemonNo */
	public static int getDaemonNo() {
		return daemonNo;
	}

	/** 取得ID */
	public static String getMyID() {
		return myID;
	}

	/** 取得主节点的IP */
	public static String getCloudMater() {
		return CloudContext.getCloudMaster();
	}

	/** 取得主节点心跳侦听端口 */
	public static int getMasterListenPort() {
		return CloudContext.getHBListenPort();
	}

	/** 取得心跳消息发送的时间间隔 */
	public static int getHelloInterval() {
		return CloudContext.getHBInterval();
	}

	/** 取得心跳不正常时，尝试重新连接的次数 */
	public static int getMaxHelloTriedTimes() {
		return CloudContext.getMaxHelloTimes4Child();
	}
}
